package cn.dankal.flyaudio.home;

import api.CurrentServiceFactory;
import cn.dankal.basiclib.rx.AbstractDialogSubscriber;
import cn.dankal.basiclib.util.ToastUtils;
import cn.dankal.business.pojo.ReasonBean;

/**
 * author: QianRui.Wu <18033405861@163.com>
 * version: V1.0.0
 * created at 2019/3/11 11:41
 * desc: 点赞的业务代码
 * note:
 * Copyright (c) 2019 Shenzhen O&M Cloud Co., Ltd. All rights reserved.
 */
public class PraiseHelper {

    public void praise(int position, int type, String uuid,PraiseCallback callback) {
        CurrentServiceFactory
                .praise_user_info(String.valueOf(type),uuid,true)
                .subscribe(new AbstractDialogSubscriber<ReasonBean>(null) {

                    @Override
                    public void onNext(ReasonBean reasonBean) {
                        callback.onPraiseSuccess(position,false);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        callback.onPraiseFailure(position,e.getMessage());
                    }
                });
    }

    public void praiseCancel(int position, int type, String uuid,PraiseCallback callback) {
        CurrentServiceFactory
                .praise_user_info(String.valueOf(type),uuid,false)
                .subscribe(new AbstractDialogSubscriber<ReasonBean>(null) {

                    @Override
                    public void onNext(ReasonBean reasonBean) {
                        callback.onPraiseSuccess(position,true);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        callback.onPraiseFailure(position,e.getMessage());
                    }
                });
    }

    interface PraiseCallback{

        void onPraiseSuccess(int position,boolean isPraise);

        void onPraiseFailure(int poistion,String errorInfo);

    }
}
